package vp.remedies.dr.home.fragment;

import java.util.ArrayList;
import java.util.List;

import vp.remedies.dr.home.R;
import vp.remedies.dr.home.activity.TypesofDiseasesActivity;
import vp.remedies.dr.home.db.AndroidSQLiteHelper;
import vp.remedies.dr.home.so.TypesofDiseasesList;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

@SuppressLint({ "ValidFragment", "NewApi" })
public class TypesOfDiseasesMetro3Fragment extends Fragment {
	public static List<TypesofDiseasesList> typesOfDiseaseList;

	public TypesOfDiseasesMetro3Fragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View rootView = inflater.inflate(R.layout.types_of_diseases_metro_3,
				container, false);

		List<TypesofDiseasesList> typesOfDiseaseList = getTypesofDiseasesList();

		LinearLayout linearLayoutType21 = (LinearLayout) rootView
				.findViewById(R.id.type21);
		LinearLayout linearLayoutType22 = (LinearLayout) rootView
				.findViewById(R.id.type22);
		LinearLayout linearLayoutType23 = (LinearLayout) rootView
				.findViewById(R.id.type23);
		LinearLayout linearLayoutType24 = (LinearLayout) rootView
				.findViewById(R.id.type24);
		LinearLayout linearLayoutType25 = (LinearLayout) rootView
				.findViewById(R.id.type25);
		LinearLayout linearLayoutType26 = (LinearLayout) rootView
				.findViewById(R.id.type26);
		LinearLayout linearLayoutType27 = (LinearLayout) rootView
				.findViewById(R.id.type27);
		LinearLayout linearLayoutType28 = (LinearLayout) rootView
				.findViewById(R.id.type28);
		LinearLayout linearLayoutType29 = (LinearLayout) rootView
				.findViewById(R.id.type29);
		LinearLayout linearLayoutType30 = (LinearLayout) rootView
				.findViewById(R.id.type30);

		final int type21 = ((TypesofDiseasesList) typesOfDiseaseList.get(20))
				.getId();
		final String typeName21 = ((TypesofDiseasesList) typesOfDiseaseList
				.get(20)).getName();
		int id1 = getResources().getIdentifier("i" + type21, "drawable",
				getActivity().getPackageName());

		linearLayoutType21.setBackgroundResource(id1);
		linearLayoutType21.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type21);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		final int type22 = ((TypesofDiseasesList) typesOfDiseaseList.get(21))
				.getId();
		final String typeName22 = ((TypesofDiseasesList) typesOfDiseaseList
				.get(21)).getName();
		int id22 = getResources().getIdentifier("i" + type22, "drawable",
				getActivity().getPackageName());
		linearLayoutType22.setBackgroundResource(id22);
		linearLayoutType22.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type22);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		final int type23 = ((TypesofDiseasesList) typesOfDiseaseList.get(22))
				.getId();
		String typeName23 = ((TypesofDiseasesList) typesOfDiseaseList.get(22))
				.getName();
		int id23 = getResources().getIdentifier("i" + type23, "drawable",
				getActivity().getPackageName());
		linearLayoutType23.setBackgroundResource(id23);
		linearLayoutType23.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type23);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		final int type24 = ((TypesofDiseasesList) typesOfDiseaseList.get(23))
				.getId();
		final String typeName24 = ((TypesofDiseasesList) typesOfDiseaseList
				.get(23)).getName();
		int id24 = getResources().getIdentifier("i" + type24, "drawable",
				getActivity().getPackageName());
		linearLayoutType24.setBackgroundResource(id24);
		linearLayoutType24.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type24);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		final int type25 = ((TypesofDiseasesList) typesOfDiseaseList.get(24))
				.getId();
		final String typeName25 = ((TypesofDiseasesList) typesOfDiseaseList
				.get(24)).getName();
		int id25 = getResources().getIdentifier("i" + type25, "drawable",
				getActivity().getPackageName());
		linearLayoutType25.setBackgroundResource(id25);
		linearLayoutType25.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type25);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		final int type26 = ((TypesofDiseasesList) typesOfDiseaseList.get(25))
				.getId();
		final String typeName26 = ((TypesofDiseasesList) typesOfDiseaseList
				.get(25)).getName();
		int id26 = getResources().getIdentifier("i" + type26, "drawable",
				getActivity().getPackageName());
		linearLayoutType26.setBackgroundResource(id26);
		linearLayoutType26.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type26);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		final int type27 = ((TypesofDiseasesList) typesOfDiseaseList.get(26))
				.getId();
		final String typeName27 = ((TypesofDiseasesList) typesOfDiseaseList
				.get(26)).getName();
		int id27 = getResources().getIdentifier("i" + type27, "drawable",
				getActivity().getPackageName());
		linearLayoutType27.setBackgroundResource(id27);
		linearLayoutType27.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type27);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		final int type28 = ((TypesofDiseasesList) typesOfDiseaseList.get(27))
				.getId();
		final String typeName28 = ((TypesofDiseasesList) typesOfDiseaseList
				.get(27)).getName();
		int id28 = getResources().getIdentifier("i" + type28, "drawable",
				getActivity().getPackageName());
		linearLayoutType28.setBackgroundResource(id28);
		linearLayoutType28.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type28);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		final int type29 = ((TypesofDiseasesList) typesOfDiseaseList.get(28))
				.getId();
		final String typeName29 = ((TypesofDiseasesList) typesOfDiseaseList
				.get(28)).getName();
		int id29 = getResources().getIdentifier("i" + type29, "drawable",
				getActivity().getPackageName());

		linearLayoutType29.setBackgroundResource(id29);
		linearLayoutType29.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type29);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		final int type30 = ((TypesofDiseasesList) typesOfDiseaseList.get(29))
				.getId();
		final String typeName30 = ((TypesofDiseasesList) typesOfDiseaseList
				.get(29)).getName();
		int id30 = getResources().getIdentifier("i" + type30, "drawable",
				getActivity().getPackageName());

		linearLayoutType30.setBackgroundResource(id30);
		linearLayoutType30.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(),
						TypesofDiseasesActivity.class);
				String diseas_type = "" + (type30);
				i.putExtra(TypesofDiseasesActivity.DISEAS_TYPE, diseas_type);
				startActivity(i);
			}
		});

		return rootView;
	}

	public static List<TypesofDiseasesList> getTypesofDiseasesList() {
		typesOfDiseaseList = new ArrayList<TypesofDiseasesList>();
		AndroidSQLiteHelper helper = AndroidSQLiteHelper.getInstance();
		/*
		 * Cursor cursor = helper .getCursorRaw(
		 * "SELECT  id , name FROM types_of_diseases_en where ORDERED BY name ASC"
		 * , null);
		 */
		String orderBy = "name" + " ASC";
		Cursor cursor = helper.getReadableDatabase().query(
				"types_of_diseases_en", new String[] { "id", "name" }, null,
				null, null, null, orderBy);

		while (cursor.moveToNext()) {
			TypesofDiseasesList diseasesList = new TypesofDiseasesList();
			int id = cursor.getInt(0);
			String name = cursor.getString(1);
			diseasesList.setId(id);
			diseasesList.setName(name);
			typesOfDiseaseList.add(diseasesList);
		}
		return typesOfDiseaseList;
	}
	 

}
